Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Jun 27, 2025

Link issues

fixes #6319

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Consolidate TCP socket client behavior into a reusable abstract base class, refactor the default client to leverage it, and modernize the interface and disposal to use asynchronous patterns.

New Features:

  • Introduce TcpSocketClientBase abstract class for common TCP client functionality.

Enhancements:

  • Refactor DefaultTcpSocketClient to inherit from TcpSocketClientBase and override core methods.
  • Update ITcpSocketClient interface to extend IAsyncDisposable and make Close return a ValueTask.
  • Modernize disposal pattern across TCP client implementation to use async disposal.

@bb-auto bb-auto bot added the enhancement New feature or request label Jun 27, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jun 27, 2025

Reviewer's Guide

Extract common TCP client logic into an abstract base class, refactor the concrete implementation to derive from it with overridden lifecycle and I/O methods, and switch the client interface to async disposal.

Class diagram for TcpSocketClientBase introduction and refactor

classDiagram
    class ITcpSocketClient {
        <<interface>>
        +bool IsConnected
        +IPEndPoint? LocalEndPoint
        +int ReceiveBufferSize
        +bool IsAutoReceive
        +Func<ReadOnlyMemory<byte>, ValueTask>? ReceivedCallBack
        +int ConnectTimeout
        +int SendTimeout
        +int ReceiveTimeout
        +void SetDataHandler(IDataPackageHandler handler)
        +ValueTask<bool> ConnectAsync(IPEndPoint endPoint, CancellationToken token)
        +ValueTask<bool> SendAsync(ReadOnlyMemory<byte> data, CancellationToken token)
        +ValueTask<Memory<byte>> ReceiveAsync(CancellationToken token)
        +ValueTask Close()
        +ValueTask DisposeAsync()
    }

    class TcpSocketClientBase {
        <<abstract>>
        +bool IsConnected
        +IPEndPoint? LocalEndPoint
        +int ReceiveBufferSize
        +bool IsAutoReceive
        +Func<ReadOnlyMemory<byte>, ValueTask>? ReceivedCallBack
        +int ConnectTimeout
        +int SendTimeout
        +int ReceiveTimeout
        +virtual void SetDataHandler(IDataPackageHandler handler)
        +abstract ValueTask<bool> ConnectAsync(IPEndPoint endPoint, CancellationToken token)
        +abstract ValueTask<bool> SendAsync(ReadOnlyMemory<byte> data, CancellationToken token)
        +abstract ValueTask<Memory<byte>> ReceiveAsync(CancellationToken token)
        +virtual ValueTask Close()
        +protected virtual ValueTask DisposeAsync(bool disposing)
        +ValueTask DisposeAsync()
    }

    class DefaultTcpSocketClient {
        +override bool IsConnected
        +override void SetDataHandler(IDataPackageHandler handler)
        +override ValueTask<bool> ConnectAsync(IPEndPoint endPoint, CancellationToken token)
        +override ValueTask<bool> SendAsync(ReadOnlyMemory<byte> data, CancellationToken token)
        +override ValueTask<Memory<byte>> ReceiveAsync(CancellationToken token)
        +override protected ValueTask DisposeAsync(bool disposing)
        +ILogger<DefaultTcpSocketClient>? Logger
    }

    ITcpSocketClient <|.. TcpSocketClientBase
    TcpSocketClientBase <|-- DefaultTcpSocketClient
Loading

File-Level Changes

Change Details Files
Introduce TcpSocketClientBase abstract class to encapsulate TCP client functionality
  • Created new abstract base class with shared properties (e.g., ReceiveBufferSize, IsAutoReceive) and abstract/virtual methods for ConnectAsync, SendAsync, ReceiveAsync, SetDataHandler, and Close
  • Implemented IAsyncDisposable pattern in the base class via DisposeAsync overloads
src/BootstrapBlazor/Services/TcpSocket/TcpSocketClientBase.cs
Refactor DefaultTcpSocketClient to extend the new base class
  • Changed inheritance from ITcpSocketClient to TcpSocketClientBase
  • Removed duplicated properties and synchronous Dispose implementation
  • Overrode key methods (IsConnected, SetDataHandler, ConnectAsync, SendAsync, ReceiveAsync, and DisposeAsync) to align with the base class
src/BootstrapBlazor/Services/TcpSocket/DefaultTcpSocketClient.cs
Update ITcpSocketClient interface to support async disposal
  • Replaced IDisposable with IAsyncDisposable on the interface
  • Changed Close method signature to return ValueTask instead of void
src/BootstrapBlazor/Services/TcpSocket/ITcpSocketClient.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#6319 Create a TcpSocketClientBase class.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto bot added this to the 9.7.0 milestone Jun 27, 2025
sourcery-ai[bot]
sourcery-ai bot previously approved these changes Jun 27, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ArgoZhang - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Jun 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.98%. Comparing base (342ff51) to head (dc822e9).
Report is 2 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##              main    #6320      +/-   ##
===========================================
- Coverage   100.00%   99.98%   -0.02%     
===========================================
  Files          714      715       +1     
  Lines        31447    31516      +69     
  Branches      4437     4447      +10     
===========================================
+ Hits         31447    31512      +65     
- Misses           0        3       +3     
- Partials         0        1       +1     
Flag Coverage Δ
BB 99.98% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ArgoZhang ArgoZhang merged commit a8c8dc7 into main Jun 27, 2025
4 of 5 checks passed
@ArgoZhang ArgoZhang deleted the refactor-tcp branch June 27, 2025 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(TcpSocketClientBase): add TcpSocketClientBase class

2 participants